package com.goblin.model.uaa.po;

import com.goblin.model.base.BaseEntity;
import lombok.Data;

import javax.persistence.*;
import java.util.List;

@Data
@Table(name = "t_test_uaa_user")
@Entity
public class User extends BaseEntity {

    private static final long serialVersionUID = 55810909236111596L;

    @Column(name = "nick_name", columnDefinition = "varchar(11) COMMENT '昵称'")
    private String nickName;

    @Column(name = "password", nullable = false, columnDefinition = " varchar(255) COMMENT '用户密码'")
    private String password;

    @Column(name = "mobile", columnDefinition = " varchar(255) COMMENT '联系电话'")
    private String mobile;

    @Column(name = "email", columnDefinition = "varchar(255) COMMENT '邮箱地址'")
    private String email;

    @Column(name = "memo", columnDefinition = " varchar(255) COMMENT '用户信息备注'")
    private String memo;

    @Column(name = "portrait", columnDefinition = " varchar(1000) COMMENT '头像图片'")
    private String portrait;

    //all: 所有情况下均进行关联操作，即save-update和delete。
    //FetchType.EAGER：急加载，加载一个实体时，定义急加载的属性会立即从数据库中加载
    @ManyToMany(fetch = FetchType.EAGER)
    @JoinTable(name = "t_test_user_role", inverseJoinColumns = @JoinColumn(name = "user_id", table = "t_uaa_user",
            referencedColumnName = "id"), joinColumns = @JoinColumn(name = "role_id", table = "t_uaa_role",
            referencedColumnName = "id"), foreignKey = @ForeignKey(name = "none", value = ConstraintMode.NO_CONSTRAINT))
    private List<Role> roles;
}
